#!/bin/bash
exp=$0
lang=$1
size=$2
train1=0
train=10
javaopts=-Xmx2400m 

if [ -z "$size" ] ; then
    size="100"
fi

# Find training data
conll=./conll/data
trainsrc=`find $conll/$lang -name '*train.conll' | head -1`
test=`find $conll/$lang -name '*test.conll' | head -1`
parses=out/$lang-$size-ip

# Abort if log file already exists
if [ -f $parses.log ] ; then
	echo "Log file $parses.log already exists... aborting!"
	exit 1
fi

# Create training data
traintmp="/tmp/train.$$"
cat $trainsrc | experiments/subcorpus $size > $traintmp

# Run command
java -server -cp dist/MatrixParser.jar $javaopts org.osdtsystem.matrixparser.main.IncrementalTester $traintmp $test -eval.output1=$parses.mst.conll -eval.output2=$parses.ip.conll 2>&1 -train.iterations1=$train1 -train.iterations=$train -train.cache=false | tee $parses.log
rm $traintmp

# Create conll evaluation
conll/eval.pl -g $test -s $parses.mst.conll > $parses.mst.eval
conll/eval.pl -g $test -s $parses.ip.conll > $parses.ip.eval
dtag -e "load $parses.mst.conll" -e "diff $parses.ip.conll" -e "print /tmp/dtag-diff.${PID}.ps" -e "quit"
ps2pdf /tmp/dtag-diff.${PID}.ps $parses.mst-diff-ip.pdf
rm /tmp/dtag-diff.${PID}.ps

